

import ResLoader from "../res/ResLoader";
import ResItem from "../res/ResItem";
import TSMap from "../struct/TSMap";
import { ResType } from "../res/ResInterface";
export default abstract class BaseAudioManager {

    protected sourcePool: TSMap<string, any> = new TSMap();

    // static MAX_NUM: number = cc.audioEngine.getMaxAudioInstance();

    private loader: ResLoader = null;

    // protected audioManager:AudioManager;

    constructor(loader: ResLoader) {
        // this.dir = dir;
        this.loader = loader;
    }

    clear() {

    }
    
    //或者支持的最大音频数量。
    abstract getMaxNum():number;

    play(name: string, isLoop?: boolean) {
        // if(!this.audioManager.getMusicFlag()){
        //     return;
        // }
        // name = this.getDir() + name;
        // if(BaseAudioManager.sourcePool.size() < BaseAudioManager.MAX_NUM){    
        this.loader.loadRes(name, ResType.AudioClip, (err, item: ResItem) => {
            if (err) {
                cc.log("AudioSource err ", err);
                return;
            }

            this.add(name, item.getRes(), isLoop);
        });
        // }
    }

    abstract add(name, res, isLoop);

    abstract pause(name?: string);

    abstract resume(name?: string);

    abstract stop(name?: string);

    abstract setVolume(count: number);

    abstract isPlaying(): boolean;

    static pauseAll() {
        cc.audioEngine.pauseAllEffects();
    }
    static resumeAll() {
        cc.audioEngine.resumeAllEffects();
    }
    static stopAll() {
        cc.audioEngine.stopAllEffects();
    }


}
